﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ATA.OLSD.ScoringService.Entities;

namespace CPAScoringPerformanceTester.TestTask
{
    public class ScoreTaskDetailTask : TestTaskBase
    {
        private UserAccessTicket ticket;
        public static string TaskName = "Score Task Detail Test";
        public PersonTask Task { get; private set; }

        public ScoreTaskDetailTask(UserAccessTicket ticket)
        {
            this.ticket = ticket;
        }

        public override void Setup()
        {
            base.Setup();

            if (!ScoreTaskDetailSettings.Instance.TaskId.HasValue)
            {
                Message = ERROR_TASK_NOT_SPECIFIED;
                IsError = true;
                return;
            }

            if (ticket == null)
            {
                Message = ERROR_BAD_ACCOUNT;
                IsError = true;
            }
        }

        public override bool Execute()
        {
            try
            {
                Client = ServiceProxy.NewProxy();
                Task = Client.GetPersonTask(ticket, new ScoringRequestContext()
                { 
                    Type = TaskType.Scoring,
                    TaskId = ScoreTaskDetailSettings.Instance.TaskId.Value
                });
                return Task != null;
            }
            catch (Exception ex)
            {
                Message = ex.Message;
                return false;
            }
            finally
            {
                Client.CloseConnection();
            }
        }
    }
}
